<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>取回一个文档 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/distrib-read.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/distrib-read.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/distrib-read.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/distrib-read.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="getting-started.html">基础入门</a></span>
»
<span class="breadcrumb-link"><a href="distributed-docs.html">分布式文档存储</a></span>
»
<span class="breadcrumb-node">取回一个文档</span>
</div>
<div class="navheader">
<span class="prev">
<a href="distrib-write.html">« 新建、索引和删除文档</a>
</span>
<span class="next">
<a href="_partial_updates_to_a_document.html">局部更新文档 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="distrib-read"></a>取回一个文档<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/040_Distributed_CRUD/20_Retrieving.asciidoc">edit</a>
</h2>
</div></div></div>
<p>可以从主分片或者从其它任意副本分片检索文档 ，如下图所示 <a class="xref" href="distrib-read.html#img-distrib-read" title="取回单个文档">Figure 10, “取回单个文档”</a>.</p>
<div id="img-distrib-read" class="imageblock">
<div class="content">
<img src="../images/elas_0403.png" alt="取回单个文档">
</div>
<div class="title">Figure 10. 取回单个文档</div>
</div>
<p>以下是从主分片或者副本分片检索文档的步骤顺序：</p>
<p>1、客户端向 <code class="literal">Node 1</code> 发送获取请求。</p>
<p>2、节点使用文档的 <code class="literal">_id</code> 来确定文档属于分片 <code class="literal">0</code> 。分片 <code class="literal">0</code> 的副本分片存在于所有的三个节点上。
   在这种情况下，它将请求转发到 <code class="literal">Node 2</code> 。</p>
<p>3、<code class="literal">Node 2</code> 将文档返回给 <code class="literal">Node 1</code> ，然后将文档返回给客户端。</p>
<p>在处理读取请求时，协调结点在每次请求的时候都会通过轮询所有的副本分片来达到负载均衡。</p>
<p>在文档被检索时，已经被索引的文档可能已经存在于主分片上但是还没有复制到副本分片。
在这种情况下，副本分片可能会报告文档不存在，但是主分片可能成功返回文档。
一旦索引请求成功返回给用户，文档在主分片和副本分片都是可用的。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="distrib-write.html">« 新建、索引和删除文档</a>
</span>
<span class="next">
<a href="_partial_updates_to_a_document.html">局部更新文档 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>